'''
Created on Apr 23, 2012
TC ID: Ecom_5024
Desc: Kiem thu chuc nang thiet lap thanh vien cho nhom nguoi dung
@author: lavang
'''
import unittest
from HTMLTestRunner import HTMLTestRunner
import time
from Functions.globalFunc import preCondition, readData, endCondition
from Functions.loginPageFunc import login
from Functions.userGroupsFunc import clickOnUserGroups, ClickOnGroup,\
    clickOnTabGroupUser, setGroupMember, fc_set, isGroupMemberSet
from Functions.logoutFunc import logout

username=readData("username")
password=readData("password")
tm_userGroupName=readData("groupName",index=3)
tm_user=readData("username",index=2)
tm_set=fc_set
class Ecom_5024(unittest.TestCase):


    def setUp(self):
        preCondition(self)

    def test_Ecom_5024(self):
        print "Buoc 1: Dang nhap vao website"
        login(self,username,password)
   
        print "Buoc 2: Click vao User groups"
        clickOnUserGroups(self)
        
        print "Buoc 3: Click vao group muon thiet lap thanh vien"
        ClickOnGroup(self,tm_userGroupName)
        
        print "Buoc 4: Click vao tab Group lesson"
        clickOnTabGroupUser(self)
        
        print "Buoc 5: Thiet lap thanh vien cho chom"
        setGroupMember(self,tm_user,set=tm_set)
        
        print "Buoc 6: Dang xuat tai khoan va dang nhap lai"
        logout(self)
        login(self,username,password)
        
        print "Buoc 7: Click vao User group"
        clickOnUserGroups(self)
        
        print "Buoc 8: click vao group vua thiet lap thanh vien"
        ClickOnGroup(self,tm_userGroupName)
        
        print "Buoc 9: Click vao tab Group users"
        clickOnTabGroupUser(self)
         
        print "Buoc 10: Kiem tra thanh vien duoc thiet lap"
        self.assertTrue(isGroupMemberSet(self,tm_user), "Failed!")
        print "Passed! Thiet lap thanh vien thanh cong"
   
    def tearDown(self):
        endCondition(self)


    

if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    testSuite = unittest.TestSuite()
    suite = unittest.TestLoader().loadTestsFromTestCase(Ecom_5024)
    dateTime = time.strftime('%Y%m%d_%H_%M_%S')
    buf = file("../../Report/TestResults" + "_" + dateTime + ".html",'wb')
    runner = HTMLTestRunner(
                    stream=buf,
                    title='Test Results',
                    description='Kiem thu chuc nang thiet lap thanh vien nhom nguoi dung'
                    )
    runner.run(suite)